// Source File Name:   CPNameAndType.java

package com.vhly.classfile;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;

// Referenced classes of package com.vhly.classfile:
//            CPEntry

public class CPNameAndType
        extends CPEntry {

    private int sig_index;
    private int name_index;
    public static final int tag = 12;

    public CPNameAndType() {
        name_index = 0;
        sig_index = 0;
    }

    public CPNameAndType(int i, int j) {
        name_index = i;
        sig_index = j;
    }

    public int getNameIndex() {
        return name_index;
    }

    public int getSigIndex() {
        return sig_index;
    }

    public void setNameIndex(int i) {
        name_index = i;
    }

    public void setSigIndex(int i) {
        sig_index = i;
    }

    public void write(DataOutputStream dout)
            throws IOException {
        dout.write(12);
        dout.writeShort(name_index);
        dout.writeShort(sig_index);
    }

    public void read(DataInputStream din)
            throws IOException {
        name_index = din.readUnsignedShort();
        sig_index = din.readUnsignedShort();
    }

    public int getType() {
        return 12;
    }

    /**
     * 比较指定元素是否和自身相等
     *
     * @param e CPEntry
     * @return 0 equals -1 no
     */
    public boolean equalsTo(CPEntry e) {
        CPNameAndType cpd = (CPNameAndType) e;
        return cpd.name_index == this.name_index && cpd.sig_index == this.sig_index;
    }
}